{extend name="public/base" /}

{block name="title"}<title>奖票事件</title>{/block}

{block name="pjax_container"}

<style>    
    label {
        display: flex;
        letter-spacing: 1px;
        align-items: center;
        white-space: nowrap;

        margin-bottom: 30px;
        font-weight: bold;
    }

    #form1 {
        display: flex;
        align-items: center;
        margin-top: 30px;
    }

    /* .sreachs{
 transform:scale(1.2);
} */
    p {
        margin: 0 10px 0 0;
    }



    .modal-body {
        padding: 27px;
        width: 856px;
        height: 700px;
        display: flex;
    }
    .table-body {
        width: 530px;
        height: 470px;
        border-radius: 6px;
        background-color: #eee;
    }
    .table-left {
        margin-right: 2%;
        width: 49%;
        height: 100%;
        float: left;
        border: 1px solid #eee;
        background-color: #fff;
    }
    .modal-left {
        width: 66%;
        height: 100%;
    }

    .table-right {
        width: 49%;
        height: 100%;
        border: 1px solid #eee;
        float: left;
        background-color: #fff;
    }
    input[type="number"] {
        border: none;
        border: 1px solid #ccc;
        width: 60px;
        margin: 0;
    }

    ::-webkit-input-placeholder {
        /* WebKit browsers */
        text-align: center;
    }

    :-moz-placeholder {
        /* Mozilla Firefox 4 to 18 */
        text-align: center;
    }

    ::-moz-placeholder {
        /* Mozilla Firefox 19+ */
        text-align: center;
    }

    :-ms-input-placeholder {
        /* Internet Explorer 10+ */
        text-align: center;
    }

    tr>th,
    td {
        text-align: center;
    }

    .content-header>.breadcrumb>li {
        color: #999;
    }

    .content-header>.breadcrumb>.active {
        color: #666;
    }

    .content-header {
        height: 51px;

    }

    .btn-primary {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 5px 10px;
        line-height: 24px;
    }

    .box-primary {
        border-top-color: #ecf0f5 !important;
        border-top-width: 16px;

    }

    .btn-primary:hover {
        background-color: #1890FF;
        color: #fff;
        border: none;
        opacity: .9;
        border-radius: 6px !important;
    }

    .delete-one {
        background-color: ff4141 !important;
        margin-left: 15px;
        border-radius: 6px;
    }

    .sreachs {
        background-color: #1890FF;
        color: #fff;
        border: none;
        border-radius: 6px !important;
        margin-left: 15px;
        padding: 7px 15px;
        height: 34px !important;
    }

    .type_explode {
        color: #fff;
        background-color: #d9534f;
        border-radius: 6px;
        border: none;
    }

    .input-group {
        overflow: hidden;

    }
    .input-group label {
        width: 335px;
        float: left;
        justify-content: flex-start;
        display: flex;
        align-items: center;
        margin-left: 30px;
    }

    .select2-selection {
        width: 256px;
    }

    .select2 {
        width: 256px !important;
    }

    .input-group-btn {
        margin-left: 10px;
    }
    .modal-content {
        position: relative;
        height: 700px;
    }
    .modal-footer {
        position: absolute;
        width: 100%;
        bottom: 0;
        right: 0;
    }
    .reward {
        position: relative;
    }
    .reward-left {
        position: absolute;
        top: 45px;
        /* left: -45px; */
    }
    .reward-right {
        position: absolute;
        top: 45px;
        left: 110px;
    }
    .auditor {
        position: relative;
    }
    .auditor-left {
        position: absolute;
        top: 0;
        right: 200px;
    }
    .auditor-right {
        position: absolute;
        top: 0;
        right: 70px;
    }
    .cause-box {
        position: relative;
    }
    .cause {
        position:absolute;
        top: 0;
        left: -5px;
    }
    #personTip {
        position: fixed;
        z-index: 999;
        left: 50%;
        top: 66px;
        transform: translateX(-50%);
        padding: 10px 50px;
        background-color: #ffbf1e!important;
        border-radius: 7px;
    }
    .reward-obj h5 {
        font-weight: 700;
    }
    .prints_item p{
        height: 21px;
    }
</style>

<section class="content-header">
    <ol class="breadcrumb">
        <li>奖票管理</li>
        <li class="active"> 我的奖票列表</li>
    </ol>
</section>
<section class="content">
    <div class="alert alert-warning" role="alert" id="personTip" style="display: none">请选择打印对象</div>
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-body table-responsive">
                    <table class="table table-bordered table-hover">
                        <tr>

                            <th>奖扣对象</th>
                            <th>奖扣时间</th>
                            <th>事件名称</th>
                            <th>B分</th>
                            <th>记录人</th>
                            <th>初审人</th>
                            <th>终审人</th>
                            <th>奖票状态</th>
                            <th>事件描述</th>
                        </tr>
                        {volist name="$list" id="v"}
                        <tr>
                            <td>{$user_list[$v['user_id']]}</td>
                            <td>{:date('Y-m-d', $v.prize_buckle_time)}</td>
                            <td>{$v.name}</td>
                            <td>{$v.integral_b}</td>
                            <td>{$user_list[$v['record_user_id']]??''}</td>
                            <td>{$user_list[$v['first_check_user_id']]??''}</td>
                            <td>{$user_list[$v['last_check_user_id']]??''}</td>
                            <td>{$is_print_arr[$v['is_print']]}</td>
                            <td>{$v.event_desc}</td>
                        </tr>
                        {/volist}
                    </table>
                </div>
                <div class="box-footer clearfix">
                    {$list->render()}
                </div>
            </div>
        </div>
    </div>
    </div>

    <!-- Modal -->
    <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog"
        aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h3 class="modal-title" id="exampleModalLabel">积分奖励通知单</h3>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="position: absolute; right: 15px; top: 22px;">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="prints_list" style="display:flex;flex-direction:column;width: 555px;max-height: 510px;overflow-y: auto;">
                        
                        <!-- <div class="prints_item">
                            <label style="display: flex;letter-spacing: 1px; margin-bottom: 10px; align-items: baseline;" class="reward-obj">
                            <h5>奖分对象</h5>
                            <p class="code1 prints" style="text-align:center; margin-top: 45px; margin-left: 30px; margin-bottom: 10px; border-bottom: 1px dotted #ccc; width: 60px;"></p>
                            </label>
                            <label style="display: flex;letter-spacing: 1px; margin-left: 50px;margin-bottom: 5px;" class="cause-box">
                                <span class="cause">因</span>
                                <p class="code2 prints" style="text-align:left; width: 100%; margin-left: 40px; margin-bottom: 10px; margin-right: 20px; border-bottom: 1px dotted #ccc; "> </p>
                            </label>
                            <label style="display: flex; letter-spacing: 1px;  margin-bottom: 10px;" class="reward">
                                <span class="reward-left">特给予</span>
                                <p class="code3 prints" style="text-align: center; width: 40px; margin-left: 60px; margin-top: 40px; border: none; border-bottom: 1px dotted #ccc; margin-right: 10px; margin-bottom: 10px; display: flex; letter-spacing:1px">
                                </p>
                                <span class="reward-right">分的奖励，感谢你的优秀表现和做出的贡献!</span>
                            </label>
                            <label style="display: flex;letter-spacing: 1px; float: right; clear: right;margin-bottom: 10px; overflow: hidden;" class="auditor">
                                    <span class="auditor-left">初审人:</span>
                                    <span class="code4 prints" style="float: left; text-align:center; width: 60px;height: 21px; border-bottom: 1px dotted #ccc; margin-left: 198px; margin-bottom: 10px;">
                                    </span>
                                    <span class="auditor-right">终审人:</span>
                                    <span class=" code5 prints" style="float: left; text-align:center; width: 60px;height: 21px; border-bottom: 1px dotted #ccc; margin-left: 80px; margin-bottom: 10px;">
                                    </span>
                            </label>
                            <label style="display: flex;letter-spacing: 1px; float: right; clear: right;  margin-bottom: 10px;justify-content: center;align-items: baseline;">
                                <span class="code6 prints"  style="float: left; text-align:right; border-bottom: 1px dotted #ccc; margin: 28px 0; margin-left: 38px; margin-right: 20px"></span>年
                                <span class="code7 prints" style="float: left; text-align:right; border-bottom: 1px dotted #ccc;margin: 28px 20px;"></span>月
                                <span class="code8 prints" style="float: left; text-align:right; border-bottom: 1px dotted #ccc; margin: 28px 20px;"></span>日
                            </label>
                        </div> -->
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" onclick="dayin()">打印</button>
                </div>
            </div>
        </div>
    </div>
</section>
<script src="__STATIC__/global/jQuery/jquery-migrate-1.2.1.min.js"></script>
<script src="__STATIC__/global/jQuery/jquery.jqprint-0.3.js"></script>
<script>
    let printing = document.getElementById("printing");
    let checkbox = document.querySelectorAll("input[type='checkbox']");
    let user_name, name, integral_b, first_check_user_name, prize_buckle_time;
    let id = []; 
    printing.onclick = function () {
        var checkLength = $(".icheckbox_minimal-blue[aria-checked='true']").length
        if(!checkLength) {
            $("#personTip").slideDown(200).delay(1500).slideUp(200)
            this.setAttribute("data-toggle", "")
        }else {
            this.setAttribute("data-toggle", "modal")
            for (let i = 0; i < checkbox.length; i++) {
                let checkboxi = checkbox[i];
                let checkboxFq = checkboxi.parentNode.getAttribute("aria-checked");
                if (checkboxFq == "true" && checkboxi.value != 'on') {
                    // id = checkboxi.value
                    id.push(checkboxi.value);
                }
            }
            // id = $(".icheckbox_minimal-blue[aria-checked='true']").find(".checkbox").val();
            $.ajax({
                type: "GET",
                url: "{:url('printer')}",
                data: {
                    id
                },
                success: function (data) {
                    console.log(data);
                    var print_item = '';
                    $.each(data.data, function (index, value){
                        let years = value.prize_buckle_time.slice(0, 4);
                        let month = value.prize_buckle_time.slice(5, 7);
                        let day = value.prize_buckle_time.slice(8, 10);
                        print_item += '<div class="prints_item"> <label style="display: flex;letter-spacing: 1px; margin-bottom: 10px; align-items: baseline;" class="reward-obj"> <h5>奖分对象</h5> <p class="code1 prints" style="text-align:center; margin-top: 45px; margin-left: 35px; margin-bottom: 10px; border-bottom: 1px dotted #ccc; width: 60px;"> '+value.user_name+'</p> </label> <label style="display: flex;letter-spacing: 1px; margin-left: 50px;margin-bottom: 5px;" class="cause-box"> <span class="cause">因</span> <p class="code2 prints" style="text-align:left; width: 100%; margin-left: 45px; margin-bottom: 10px; margin-right: 20px; border-bottom: 1px dotted #ccc; "> '+value.name+'</p> </label> <label style="display: flex; letter-spacing: 1px; margin-bottom: 10px;" class="reward"> <span class="reward-left">特给予</span> <p class="code3 prints" style="text-align: center; width: 40px; margin-left: 60px; margin-top: 42px; border: none; border-bottom: 1px dotted #ccc; margin-right: 10px; margin-bottom: 10px; display: flex; letter-spacing:1px">'+value.integral_b+' </p> <span class="reward-right">分的奖励，感谢你的优秀表现和做出的贡献!</span> </label> <label style="display: flex;letter-spacing: 1px; float: right; clear: right;margin-bottom: 10px; overflow: hidden;" class="auditor"> <span class="auditor-left">初审人:</span> <span class="code4 prints" style="float: left; text-align:center; width: 60px;height: 21px; border-bottom: 1px dotted #ccc; margin-left: 213px; margin-bottom: 10px;"> '+value.first_check_user_name+'</span> <span class="auditor-right">终审人:</span> <span class=" code5 prints" style="float: left; text-align:center; width: 60px;height: 21px; border-bottom: 1px dotted #ccc; margin-left: 85px; margin-bottom: 10px;"> '+value.last_check_user_name+'</span> </label> <label style="display: flex;letter-spacing: 1px; float: right; clear: right;  margin-bottom: 10px;justify-content: center;align-items: baseline;"><span class="code6 prints"  style="float: left; text-align:right; border-bottom: 1px dotted #ccc; margin-top: 31px;margin-bottom: 47px; margin-left: 25px; margin-right: 20px">'+years+'</span>年<span class="code7 prints" style="float: left; text-align:right; border-bottom: 1px dotted #ccc;margin-top: 31px;margin-bottom: 47px;margin-left: 20px; margin-right: 20px;">'+month+'</span>月<span class="code8 prints" style="float: left; text-align:right; border-bottom: 1px dotted #ccc; margin-top: 31px;margin-bottom: 47px;margin-left: 20px; margin-right: 25px;">'+day+'</span>日 </label></div>'
                    });
                    $(".prints_list").html("");
                    $(".prints_list").append(print_item);
                    // user_name = data.user_name;
                    // prize_buckle_time = data.prize_buckle_time;
                    // name = data.name;
                    // integral_b = data.integral_b;
                    // first_check_user_name = data.first_check_user_name;
                    // prize_buckle_time = data.prize_buckle_time;
                    
                    // $(".code1").text(user_name);
                    // $(".code2").text(name);
                    // $(".code3").text(integral_b);
                    // $(".code4").text(first_check_user_name);
                    // $(".code5").text(user_name);
                    // $(".code6").text(datayue);
                    // $(".code7").text(datayue2);
                    // $(".code8").text(datayue3);
                }
            });
        }
    }

    $(function () {
        $(".select2").select2({
            language: "zh-CN"
        });
        // 列表部分 全选
        $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
            checkboxClass: 'icheckbox_minimal-blue',
            radioClass: 'iradio_minimal-blue'
        });
        $('.checkbox-toggle').on('ifChecked', function (event) {
            var _this = $(this);
            var _table = _this.closest('.table');
            _table.find("tr td input[type='checkbox']").iCheck("check");
        });
        $('.checkbox-toggle').on('ifUnchecked', function (event) {
            var _this = $(this);
            var _table = _this.closest('.table');
            _table.find("tr td input[type='checkbox']").iCheck("uncheck");
        });
        // 改为单选
        // $('.checkbox').on('ifChecked', function (event) {
        //     var _this = $(this);
        //     var _table = _this.closest("tr");
        //     _table.siblings().find("td input[type='checkbox']").iCheck("uncheck");
        //     // $(this).iCheck("check");
        //     // _table.find("tr td input[type='checkbox']").iCheck("check");
        // });
    });

    // function dayin() {
    //     //判断iframe是否存在，不存在则创建iframe
    //     var iframe = document.getElementById("print-iframe");
    //     if (!iframe) {
    //         var el = document.querySelector("#exampleModalCenter .modal-body");
    //         iframe = document.createElement('IFRAME');
    //         var doc = null;
    //         iframe.setAttribute("id", "print-iframe");
    //         iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
    //         document.body.appendChild(iframe);
    //         doc = iframe.contentWindow.document;
    //         //这里可以自定义样式
    //         //doc.write("<LINK rel="stylesheet" type="text/css" href="css/print.css">");
    //         doc.write('<div>' + el.innerHTML + '</div>');
    //         doc.close();
    //         iframe.contentWindow.focus();
    //     }
    //     iframe.contentWindow.print();
    //     console.log(iframe.contentWindow.print());
    //     if (navigator.userAgent.indexOf("MSIE") > 0) {
    //         document.body.removeChild(iframe);
    //     }
    // }

    // 打印插件jqprint
    function dayin() {
        let id = [];
        let checkbox = document.querySelectorAll("input[type='checkbox']");
        for (let i = 0; i < checkbox.length; i++) {
            let checkboxi = checkbox[i];
            let checkboxFq = checkboxi.parentNode.getAttribute("aria-checked");
            if (checkboxFq == "true") {
                if(checkboxi.value != 'on'){
                    id.push(checkboxi.value);
                }
            }
        }
        // id = $(".icheckbox_minimal-blue[aria-checked='true']").find(".checkbox").val();
        // console.log(id);


        // 修改打印状态
        $.ajax({
            type: "GET",
            url: "{:url('printerUpdate')}",
            data: {
                id
            },
            success: function (res) {
                console.log(666);
                if(res.code == 0){
                    $(".prints").jqprint();
                }else{
                    $.amaran({'message':res.msg});
                }
            }
        });
         // $(".prints").jqprint();
    }

    var now = new Date();
    var yy = now.getFullYear(); //年
    var mm = now.getMonth() + 1; //月
    var dd = now.getDate(); //日
    var hh = now.getHours(); //时
    var ii = now.getMinutes(); //分
    var ss = now.getSeconds(); //秒
    var time = yy + "-";
    if (mm < 10) time += "0";
    time += mm + "-";
    if (dd < 10) time += "0";
    time += dd + " ";
    if (hh < 10) time += "0";
    time += hh + ":";
    if (ii < 10) time += '0';
    time += ii + ":";
    if (ss < 10) time += '0';
    time += ss;
    layui.use(['laydate'], function () {
        var laydate = layui.laydate;
        var layer_index = ''; //加载层
        laydate.render({
            range: true,
            elem: '.lay_date',
            max: time,
        });
    });

    function xls_explode() {
        window.location.href = "{:url('Ticket/index')}?" + $('#form1').serialize() + '&export=1';
        return false;
    }
</script>


<!-- 弹框样式引入 -->
<link rel="stylesheet" href="__STATIC__/global/an_tree_css/an_tree_css.css">
<!-- Modal 弹出层重写 部门单选  id="myModal_single"-->
<div class="modal fade" id="myModal_department_single" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="width:543px;height: 635px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">部门选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left" style="width:485px;">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input name="search_user_name" type="text" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                    style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;">
                                    <span class="glyphicon glyphicon-search"></span>
                                </button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body" style="width: 485px">
                        <div class="table-left" style="width: 100%;">
                            <div class="an_tree search_hide">

                            </div>
                            <div class="search_show" style="display: flex;  flex-direction: column;padding: 20px 10px;">

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<style>
.a{
    flex-direction: row;
}
</style>
</div>
<!-- 部门弹窗操作 部门单选   -->
<script>
    var now_item_name;
    var now_item_id;
    $(".department_id_name").focus(function () {
        $('#myModal_department_single').modal('show');
        // double_max = $("input[name='double_max']").val();
        now_item_name = $(this);//节点
        now_item_id = $(".department_id");//节点
        // first_id = $("input[name='first_check_user_id']").val();//id值
        // user_type = 2;
    });

</script>
<!-- 树结构js操作 部门单选  -->
<script>
    $("#myModal_department_single .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    $("#myModal_department_single").on("click", ".an_tree_txt", function () {
        $('#myModal_department_single').modal('hide');
        now_item_name.val($(this).html());
        now_item_id.val($(this).attr("data_id"));
    });
    $("#myModal_department_single").on("click", ".search_btn", function () {
        var item = $("#myModal_department_single .an_tree_txt");
        var search_name = $("#myModal_department_single input[name='search_user_name']").val();
        $("#myModal_department_single .search_show").html("");
        if(search_name == ""){
            $("#myModal_department_single .search_hide").show();
            $("#myModal_department_single .search_show").removeClass("an_tree");
        }else{
            $("#myModal_department_single .search_hide").hide();
            $("#myModal_department_single .search_show").show();
            var content = "";
            for (let i = 0; i < item.length; i++) {
                var name = item.eq(i).html();
                if (name.indexOf(search_name) != -1) {
                    content += item.eq(i).prop("outerHTML");
                }
                // console.log(name);
            }
            $("#myModal_department_single .search_show").append(content)
        }
        
    });
</script>
<!-- 递归填充目录 部门单选  -->
<script>
    var department = "";
    $.ajax({
        type: 'get',
        url: "{:url('base/base_department_page')}",
        dataType:"json",
        async: false,
        success: function (data) {
            // eventList = JSON.parse(data);
            department = data;
        }
    })
    var an_tree = ergodic(department)
    $("#myModal_department_single .an_tree").append(an_tree);
    function ergodic(data) {
        var content = '';
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>

<!-- Modal 弹出层重写 人员单选  -->
<div class="modal fade" id="myModal_single" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="width: 585px">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                        aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" >人员选择</h4>
            </div>
            <div class="modal-body">
                <div class="modal-left">
                    <div class="modal-left-title" style="margin-bottom: 20px;">
                        <div class="input-group">
                            <input name="search_user_name" type="text" class="form-control" placeholder="">
                            <span class="input-group-btn">
                                <button class="btn btn-info search_btn" type="button"
                                    style="width: 47px; height: 34px; background-color: #1890FF;border: none;outline: none;">
                                    <span class="glyphicon glyphicon-search"></span>
                                </button>
                            </span>
                        </div>
                    </div>
                    <div class="input-group table-body">
                        <div class="table-left">
                            <div class="an_tree">

                            </div>
                        </div>
                        <div class="table-right">
                            <div class="an_tree_list">
                                <div class="an_list_title">

                                </div>
                                <div class="an_list_con">
                                    <!-- <div class="an_list_item">
                                        <div class="item_info">
                                            <span class="name">aaa</span>/
                                            <span>88</span>/
                                            <span>部门</span>
                                        </div>
                                        <div class="item_box item_box_check"><i class="fa fa-check"></i></div>
                                    </div> -->
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary popups_submit">确认</button>
            </div>
        </div>
    </div>

</div>
<!-- 单选弹窗操作  -->
<script>

    var now_item_name;//名字输入框
    var now_item_id;//id输入框
    //确认按钮
    $('#myModal_single .popups_submit').click(function (e) {
        $('#myModal_single').modal('hide');
        var checked = $(".an_tree_list").find(".list_item_check");
        now_item_name.val(checked.attr("user_name"));
        now_item_id.val(checked.attr("user_id"));
        now_item_name.attr("limits_b",checked.attr("limits_b"))
    });
    //当弹窗关闭时执行重置弹窗
    $('#myModal_single').on('hidden.bs.modal', function () {
        // 执行一些动作...重置弹窗
        $(".an_tree_list .an_list_title").html("");
        $(".an_tree_list .an_list_con").html("");
        $(".tree_txt_active").removeClass("tree_txt_active");
        $(".an_tree_pack").hide();
        $(".an_tree .fa").removeClass("fa-caret-down").addClass("fa-caret-right");
        $("#myModal_single input[name='search_user_name']").val("");
    });
    // 奖扣对象
    $("input[name='user_id_name']").focus(function () {
        $('#myModal_single').modal('show');
        now_item_name = $(this);
        now_item_id = $("input[name='user_id']");//节点
    });
    // 记录人
    $("input[name='record_user_name']").focus(function () {
        $('#myModal_single').modal('show');
        now_item_name = $(this);
        now_item_id = $("input[name='record_user_id']");//节点
    });
    // 初审人
    $("input[name='first_check_user_name']").focus(function () {
        $('#myModal_single').modal('show');
        now_item_name = $(this);//节点
        now_item_id = $("input[name='first_check_user_id']");//节点
    });
    // 终审人
    $("input[name='last_check_user_name']").focus(function () {
        $('#myModal_single').modal('show');
        now_item_name = $(this);//节点
        now_item_id = $("input[name='last_check_user_id']");//节点
    });
</script>
<!-- 树结构js操作 单选  -->
<script>
    $("#myModal_single .an_tree").on("click", ".fa", function () {
        $(this).toggleClass("fa-caret-down");
        $(this).toggleClass("fa-caret-right");
        $(this).parents(".an_tree_set").eq(0).children(".an_tree_pack").toggle();
    });
    $("#myModal_single").on("click", ".an_tree_txt,.search_btn", function () {
        $(".an_tree").find(".tree_txt_active").removeClass("tree_txt_active");
        $(this).addClass("tree_txt_active");
        var department_id = $(this).attr("data_id");
        var department_name = $(this).html();
        var user_name = $("#myModal_single input[name='search_user_name']").val();
        // console.log(user_name);
        $.ajax({
            type: 'get',
            url: "{:url('base/base_department_per')}",
            data: {'department_id' : department_id,'user_name' : user_name},
            dataType:"json",
            success: function (data) {
                // var json = JSON.parse(data);
                // console.log(data);
                var content = '';
                $.each(data, function (index, value) {
                    if(value.limits==undefined){
                         var limits=0;
                    }else{
                        var limits=value.limits.b;
                    }
                    content += '<div class="an_list_item" user_name="'+value.name+'" user_id="'+value.id+'" limits_b="'+limits+'"><div class="item_info"><span class="name">' + value.name + '</span>/<span>' + value.job_number + '</span>/<span>' + value.department_name + '</span></div><div class="item_box "><i class="fa fa-check"></i></div></div>'
                });
                $('.an_list_con').html("");
                $('.an_list_con').append(content);
                $('.an_list_title').html(department_name + data.length + '人');
            }
        })
    });
    $("#myModal_single .an_tree_list").on("click", ".an_list_item", function () {
        $(this).siblings().removeClass("list_item_check");
        $(this).toggleClass("list_item_check")
    })
</script>
<!-- 递归填充目录 单选  -->
<script>
    var an_tree = ergodic(department);
    $("#myModal_single .an_tree").append(an_tree);
    function ergodic(data) {
        var content = '';
        $.each(data, function (index, value) {
            if (value.children != "") {
                var children = ergodic(value.children);
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"><i class="fa fa-caret-right"></i></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack">' + children + '</div></div>';
            } else {
                content += '<div class="an_tree_set"><div class="an_tree_entry"><div class="an_tree_main"><span class="an_tree_icon"></span><span class="an_tree_txt" data_id="' + value.id + '" data_pid="' + value.pid + '">' + value.title + '</span></div></div><div class="an_tree_pack"></div></div>';
            }
        });
        return content;
    }
</script>
{/block}